<template>
  <div class="elm-edit">
    <elm-page-bb>
      <el-form ref="model" :model="model" size="small" label-width="80px">
        <elm-row>
          <el-form-item label="提交人" prop="create_user" :rules="[{ required: true, message: '必须填写'}]">
            <elm-ei v-model="model.create_user" disabled></elm-ei>
          </el-form-item>
          <el-form-item label="相关项目" prop="pj_code">
            <elm-select-input v-model="model.pj_code" url="/business/my/GetPjData" :show-id="true"></elm-select-input>
          </el-form-item>
        </elm-row>
        <el-form-item label="工作内容" prop="work" :rules="[{ required: true, message: '必须填写'}]">
          <el-input  type="textarea" :rows="2" v-model="model.work"></el-input>
        </el-form-item>
        <elm-row>
        <el-form-item label="工作时长" prop="hour">
          <el-input-number v-model="model.hour" style="width:100%"></el-input-number>
        </el-form-item>
          <el-form-item label="是否完成" prop="is_complete">
            <el-select v-model="model.is_complete" style="width: 100%">
              <el-option label="是" value="1"></el-option>
              <el-option label="否" value="0"></el-option>
            </el-select>
          </el-form-item>
        </elm-row>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" :rows="2" v-model="model.remark"></el-input>
        </el-form-item>
      </el-form>
      <template #bottom>
        <el-button type="success" size="small" @click="submit">立即保存</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </template>
    </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {id: elm.newGuid(),create_date:new Date().toISOString().split('T')[0],create_user:null},
    }
  },
  async created() {
    this.model.create_user= await this.get_user_ei();
  },
  methods: {
    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/my/business/UpsertDaily', this.model);
      if (res == true) {
        this.v('保存成功。')
        this.close();
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      //console.log(res);
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
  }
}
</script>